﻿using SmartSapce.ServiceLocation;
using SmartSpace.Web;
using SmartSpace.Workflow;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SmartSpace.WebApp.Modules.Workflow
{
    public partial class Activity_Create : SsTemplatePage
    {
        public Guid WorkflowId { get; private set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            WorkflowId = RequestUtility.GetGuid(Request, "wfid");
            IWorkflowService service = ServiceLocator.Get<IWorkflowService>();
            _ctlEditWorkflow.Text = service.GetWorkflow(WorkflowId).Data.Caption;
        }

        protected void _ctlBtnSave_Click(object sender, EventArgs e)
        {
            IWorkflowService service = ServiceLocator.Get<IWorkflowService>();
            ActivityMetadata activity = new ActivityMetadata();
            activity.WorkflowId = WorkflowId;
            activity.Id = Guid.NewGuid();
            activity.Code = _ctlEditCode.Text;
            activity.Caption = _ctlEditCaption.Text;
            activity.IsInitial = _ctlCheckInitial.Checked;

            if (service.SaveActivity(activity).IsSuccess)
            {
                Response.Redirect(string.Format("Activity-list.aspx?wfid={0}", WorkflowId));
            }
        }
    }
}